{include file="public/header"/}
<div class="layui-container">
    <div class="layui-main user-main min-height-90vh">
        <form class="layui-form" autocomplete="off">
            <div class="layui-form layui-input-xl">
                <div class="layui-form-item">
                    <input type="text" name="real_name" lay-verify="required" lay-verType="tips" lay-reqtext="请输入姓名" placeholder="输入真实姓名" value="{$info.real_name ?? ''}" class="layui-input" lay-affix="clear" maxlength="8" minlength="2"> 
                </div>
                <div class="layui-form-item">
                    <input type="text" name="id_card" lay-verify="required|identity" lay-verType="tips" lay-reqtext="请输入身份证号" placeholder="输入身份证号" value="{$info.id_card ?? ''}" class="layui-input" lay-affix="clear"> 
                </div>
            </div>

            <div class="hr-line"></div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-bg-success" id="saveBtn" lay-submit lay-filter="saveBtn">保 存</button>
                    <a class="layui-btn layui-btn-primary" id="cancelBtn">取 消</a>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
    layui.use(['form','layer','upload'], function(){
        var layer = layui.layer, form = layui.form, upload = layui.upload, $=layui.jquery;
        
        $("#cancelBtn").on('click',function(){
            var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
            parent.layer.close(index);//关闭窗口  
        });

        form.on('submit(saveBtn)', function(data){
            var loading = layer.msg('数据处理中..', {icon: 16,shade: 0.3,time: false});
            $.ajax({
                url:'/user/update_realname',
                type:'post',
                data:data.field,
                dataType:"JSON",
                headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
                success:function(res){
                    layer.close(loading);  //返回数据关闭loading
                    if(res.code == 0){
                        $("#saveBtn").removeClass("layui-bg-success").addClass("layui-btn-disabled");
                        $("#saveBtn").attr("disabled","true");
                        layer.msg(res.msg,{icon: 1,time:1500},function(){
                            var index= parent.layer.getFrameIndex(window.name);//获取当前层
                            parent.layer.close(index);//关闭当前层
                            parent.location.reload();
                        });
                        
                    } else{
                        layer.msg(res.msg,{icon: 2});
                    }
                },
                error:function(e){
                    layer.msg('请求失败'+e.responseText,{icon: 2});
                },
                
            });
            return false;
        });

    });
    
</script>